package HomeWork01;

public class PolymorphicDemo {
    public static void main(String[] args) {

        Animal[] animals = new Animal[3];
        animals[0] = new Dog("小黑", 2, "黑");
        animals[1] = new Chick("小黄", 1, "黄");
        animals[2] = new Fish("小蓝", 3, "蓝");
        for (int i = 0; i < animals.length; i++) {
            System.out.println(animals[i].name);
            animals[i].eat();

            if (animals[i] instanceof Dog) {
                Dog dog=(Dog) animals[i];
                dog.lookHome();
            }
            if (animals[i] instanceof Chick){
                Chick chick=(Chick) animals[i];
                chick.layEggs();
            }
            if (animals[i] instanceof Swim){
                Swim s=(Swim) animals[i];
                s .swim();
            }
        }
        System.out.println();

        Master master = new Master();
        Dog dog = new Dog("小黑", 2, "黑");
        Chick chick = new Chick("小黄", 1, "黄");
        Fish fish = new Fish("小蓝", 3, "蓝");
        master.feed(dog);
        master.feed(fish);
        master.feed(chick);
    }
}